package com.tgky.ybzb.utils;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class RWUtil {


    public static void main(String[] args) {


    }


    public static void readFile(String filePath) {
        File file = new File(filePath);
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            String line;
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static List<String> readFile2List(String filePath) {

        List<String> outputList = new ArrayList<>();

        File file = new File(filePath);
        try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
            String line;
            while ((line = reader.readLine()) != null) {
                outputList.add(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }

        return outputList;

    }





    public static void writeFileOneLine(String filePath, String text) {
        File file = new File(filePath);
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
            writer.write(text);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static void writeFileList(String filePath, List<String> textList) {
        File file = new File(filePath);
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
            for (String s : textList) {
                writer.write(s);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public static void writeFileListAndNextLine(String filePath, List<String> textList) {
        File file = new File(filePath);
        try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) {
            for (String s : textList) {
                writer.write(s);
                writer.write("\n");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


}
